package com.xcl.controller;

import com.xcl.pojo.UpdateXclDeliveryList;
import com.xcl.service.DeliveryListServiceInter;
import com.zzg.entity.Driver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName DeliveryListController
 * @Description 派送列表控制器
 * @Author: xiaochaolei
 * @date 2021/7/14 19:21
 * @Version 1. 0
 */
@Controller
public class DeliveryListController {
    @Autowired
    DeliveryListServiceInter deliveryListServiceInter;

    /**
     * 多条件查询以及分页查询
     * @param page 页码数
     * @param limit 条码数
     * @param id 判断是哪个查询
     * @param waybill_id 运单号
     * @param sub_id 分站id
     * @param startDate 起始日期
     * @param endingDate 结束日期
     * @param ownerName 司机名称
     * @return 派送集合
     */
    @GetMapping(value = "/DeliveryListControllerGetXclDeliveryListAll", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object>   getXclDeliveryListAll(int page,int limit,String id,String waybill_id,String sub_id ,String startDate,String endingDate,String ownerName){
        Map<String,Object> map=new HashMap<>();
        map.put("code","0");
        map.put("msg","0");
        if (id==null){
            map.put("count", deliveryListServiceInter.getXclDeliveryListAll().size());
            map.put("data",deliveryListServiceInter.getXclDeliveryListAllByLimit(page,limit));
            return map;
        }else {
            map.put("count",deliveryListServiceInter.getXclDeliveryListAllByWhere(page,limit,waybill_id,sub_id,startDate,endingDate,ownerName).size());
            map.put("data",deliveryListServiceInter.getXclDeliveryListAllByWhere(page,limit,waybill_id,sub_id,startDate,endingDate,ownerName));
            return map;
        }
    }

    /**
     * 根据id查询派送信息
     * @param id 派送id
     * @return 派送信息
     */
    @PostMapping(value = "/DeliveryListControllerGetUpdateXclDeliveryListByDeliveryid", produces = "application/json;charset=utf-8")
    @ResponseBody
    public UpdateXclDeliveryList getUpdateXclDeliveryListByDeliveryid(String id){
        UpdateXclDeliveryList updateXclDeliveryListByDeliveryid = deliveryListServiceInter.getUpdateXclDeliveryListByDeliveryid(id);
        return updateXclDeliveryListByDeliveryid;
    }

    /**
     * 根据车辆id查询车辆信息
     * @param id  车辆id
     * @return 车辆信息
     */
    @PostMapping(value = "/DeliveryListControllerGetDriverById", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Driver getDriverById(String id){
        Driver driverById = deliveryListServiceInter.getDriverById(id);
        return driverById;
    }

    /**
     * 修改
     * @param deliveryDate
     * @param substation
     * @param delivery_id
     * @param licenseTag
     * @return
     */
    @PostMapping(value = "/DeliveryListControllerupdateXclDelivery", produces = "application/text;charset=utf-8")
    @ResponseBody
    public String updateXclDelivery(String deliveryDate, String substation, String delivery_id,String licenseTag){
        Driver driverByLicenseTag = deliveryListServiceInter.getDriverByLicenseTag(licenseTag);
        String id=driverByLicenseTag.getDriverId();
       if ( deliveryListServiceInter.updateXclDelivery(deliveryDate,substation,id,delivery_id)>0){
           return "成功";
       }
        return "失败";
    }
}
